home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / COMMUNIC / TERMINAL / 1589.ZIP / TERMDLG.C < prev    next >
Text File  |  1989-04-13  |  12KB  |  381 lines

  1.  
  2. #include "windows.h"
  3. #include <stdio.h>
  4. #include "icu_user.h"
  5. #include "term.h"
  6.  
  7. /* */
  8. /*doc************************************************************************
  9. *
  10. *     NAME
  11. *
  12. *     DescDlg() - Use to display and log error and diag. messages.
  13. *                 I use it for debugging.
  14. *
  15. *     FORMAT
  16. *
  17. *     DESCRIPTION
  18. *
  19. *     RETURN VALUE
  20. *
  21. *     MODIFIES
  22. *
  23. *     REFERENCES
  24. *
  25. *end************************************************************************/
  26. BOOL FAR PASCAL DescDlg(hWndDlg, message, wParam, lParam)
  27. HWND      hWndDlg;
  28. unsigned  message;
  29. WORD      wParam ;
  30. LONG      lParam ;
  31. {
  32.  
  33. /****************************************
  34. * start of function code                *
  35. ****************************************/
  36. switch (message)  {
  37.    case WM_CREATE:
  38.        PostMessage(hWdesc, WM_COMMAND, IDDPB2, (LONG) 0);
  39.        break;
  40.    case WM_COMMAND:
  41.        switch(wParam)  {
  42.            case IDOK:      /* Take window down         */
  43.                ShowWindow(hWndDlg,SW_HIDE);
  44.                break;
  45.            case IDDPB1:       /* Refresh list box */
  46.                SendDlgItemMessage (hWdesc,IDDLIST,LB_RESETCONTENT,0,0L);
  47.                break;
  48.            case IDDPB2:       /* Toggle Verbose messages  */
  49.                VerboseMessages = IsDlgButtonChecked(hWndDlg,IDDPB2);
  50.                break;
  51.            case IDDPB3:       /* Toggle error logging     */
  52.                LogErrors = IsDlgButtonChecked(hWndDlg,IDDPB3);
  53.                break;
  54.            default:
  55.                return FALSE;
  56.                break;
  57.            }               /* End Switch(wParam)   */
  58.        break;              /* End case WM_COMMAND: */
  59.  
  60.    default:
  61.        return FALSE;
  62.        break;
  63.    }                       /* End switch(message) */
  64. return(TRUE);
  65. }
  66.  
  67.  
  68. /* */
  69. /*doc************************************************************************
  70. *
  71. *     NAME
  72. *
  73. *     SelectDlg() - dialog box to input name for the configuration file
  74. *
  75. *     FORMAT
  76. *
  77. *     BOOL FAR PASCAL SelectDlg(hWndDlg, message, wParam, lParam)
  78. *     HWND hWndDlg;
  79. *     unsigned  message;
  80. *     WORD  wParam;
  81. *     LONG  lParam;
  82. *
  83. *     DESCRIPTION
  84. *          Displays all files ending with .cnf.  Allows the user to select
  85. *          which configuration file to use.
  86. *
  87. *     RETURN VALUE
  88. *
  89. *     MODIFIES
  90. *          ConfigFile
  91. *
  92. *     REFERENCES
  93. *
  94. *end************************************************************************/
  95. BOOL FAR PASCAL SelectDlg(hWndDlg, message, wParam, lParam)
  96. HWND      hWndDlg;
  97. unsigned  message;
  98. WORD      wParam ;
  99. LONG      lParam ;
  100. {
  101. /****************************************
  102. * local variable  declarations          *
  103. ****************************************/
  104. int     i, ret, hdl;
  105. char    temp_str[14];
  106. char    path[120];
  107. /****************************************
  108. * start of function code                *
  109. ****************************************/
  110. switch (message)  {
  111.    case WM_INITDIALOG:
  112.        SetDlgItemText(hWndDlg,IDDREQTYPE,(LPSTR)"Path:");
  113.        SetDlgItemText(hWndDlg,IDDREQSTRG,(LPSTR)"*.CNF");
  114.        DlgDirList(hWndDlg,(LPSTR)"c:*.CNF",IDDIMGLIST,IDDPATHNAME,0x4010);
  115.        break;           /* end case WM_INITDIALOG  */
  116.  
  117.    case WM_COMMAND:
  118.        switch( wParam ) {
  119.                                  /****************************************/
  120.            case IDOK:            /* user hit Select button               */
  121.                                  /****************************************/
  122.                if (!GetDlgItemText(hWndDlg,IDDREQSTRG,(LPSTR)ConfigPath,59))
  123.                    return( FALSE );
  124.                EndDialog(hWndDlg,TRUE);
  125.            break;
  126.  
  127.  
  128.            case IDDIMGLIST:
  129.                if (HIWORD(lParam) == LBN_DBLCLK) {
  130.                    if ( DlgDirSelect(hWndDlg,(LPSTR)temp_str,IDDIMGLIST) ) {
  131.                        strcpy(path,temp_str); /* user selected a directory */
  132.                        if (temp_str[1] == ':')
  133.                            strcat(path,"\\*.cnf");
  134.                        else
  135.                            strcat(path,"*.cnf");
  136.                        SetDlgItemText(hWndDlg,IDDREQSTRG,(LPSTR)"*.cnf");
  137.                        ret = DlgDirList(hWndDlg,(LPSTR)path,IDDIMGLIST,IDDPATHNAME,0x4010);
  138.                        }
  139.                    else {                      /* user selected a file name */
  140.                        SetDlgItemText(hWndDlg,IDDREQSTRG,(LPSTR)temp_str);
  141.                        SendMessage(hWndDlg,WM_COMMAND,IDOK, lParam); /* Push OK Button */
  142.                        }
  143.                    }
  144.                else if (HIWORD(lParam) == LBN_SELCHANGE) { /* user clicked string*/
  145.                    if ( DlgDirSelect(hWndDlg,(LPSTR)temp_str,IDDIMGLIST) ) {
  146.                        strcpy(path,temp_str);
  147.                        if (temp_str[1] == ':')
  148.                            strcat(path,"\\*.cnf");
  149.                        else
  150.                            strcat(path,"*.cnf");
  151.                        SetDlgItemText(hWndDlg,IDDREQSTRG,(LPSTR)path);
  152.                        }
  153.                    else                /* user selected a file name */
  154.                        SetDlgItemText(hWndDlg,IDDREQSTRG,(LPSTR)temp_str);
  155.                    }
  156.                break;
  157.  
  158.                     /*****************************************/
  159.                     /* user wants to cancel his page request */
  160.                     /*****************************************/
  161.            case IDCANCEL:
  162.                EndDialog(hWndDlg,FALSE);
  163.                break;
  164.  
  165.            default:
  166.                return(FALSE);
  167.                break;
  168.            }      /* End case WM_COMMAND: switch( wParm ) */
  169.        break;     /* End case WM_COMMAND                  */
  170.  
  171.    default:
  172.        return(FALSE);
  173.        break;
  174.    }
  175. return(TRUE);
  176. }
  177.  
  178.  
  179. /* */
  180. /*doc************************************************************************
  181. *
  182. *     NAME
  183. *
  184. *     TermAboutDlg() - dialog box for ABOUT info
  185. *
  186. *     FORMAT
  187. *
  188. *     BOOL FAR PASCAL TermAboutDlg(hWndDlg, message, wParam, lParam)
  189. *     HWND hWndDlg;
  190. *     unsigned  message;
  191. *     WORD  wParam;
  192. *     LONG  lParam;
  193. *
  194. *     DESCRIPTION
  195. *          Displays information about TERMINAL
  196. *
  197. *     RETURN VALUE
  198. *
  199. *     MODIFIES
  200. *
  201. *     REFERENCES
  202. *
  203. *end************************************************************************/
  204. BOOL FAR PASCAL TermAboutDlg(hWndDlg, message, wParam, lParam)
  205. HWND       hWndDlg;
  206. unsigned   message;
  207. WORD       wParam ;
  208. LONG       lParam ;
  209. {
  210.     switch (message)
  211.     {
  212.     case WM_INITDIALOG:
  213.         /* must return TRUE to this msg, and we do below */
  214.         break;
  215.     case WM_COMMAND:
  216.         switch (wParam)
  217.         {
  218.         case IDOK:
  219.         case IDCANCEL:
  220.             EndDialog(hWndDlg, TRUE);
  221.             break;
  222.         default:
  223.             return FALSE;
  224.         }
  225.     default:
  226.         return FALSE;
  227.     }
  228.     return TRUE;
  229. }
  230.  
  231.  
  232. /* */
  233. /*doc************************************************************************
  234. *
  235. *     NAME
  236. *
  237. *     ConfigTerm() - dialog box used to allow the user to change the terminal
  238. *                  configuration
  239. *
  240. *     FORMAT
  241. *
  242. *     BOOL FAR PASCAL ConfigTerm(hWndDlg, message, wParam, lParam)
  243. *     HWND hWndDlg;
  244. *     unsigned  message;
  245. *     WORD  wParam;
  246. *     LONG  lParam;
  247. *
  248. *     DESCRIPTION
  249. *          Allows the user to modify the terminal settings that were set
  250. *          when the configuration file was loaded.
  251. *
  252. *     RETURN VALUE
  253. *
  254. *     MODIFIES
  255. *
  256. *     REFERENCES
  257. *
  258. *end************************************************************************/
  259. BOOL FAR PASCAL ConfigTerm(hWndDlg, message, wParam, lParam)
  260. HWND      hWndDlg;
  261. unsigned  message;
  262. WORD      wParam ;
  263. LONG      lParam ;
  264. {
  265. int i, h, w;
  266. static baud, fontsize, comm, iconmode;
  267. TEXTMETRIC tm;
  268.  
  269. /****************************************
  270. * start of function code                *
  271. ****************************************/
  272. switch (message)  {
  273.    case WM_INITDIALOG:
  274.        baud = baud_rate;
  275.        iconmode = message_action;
  276.        if      ( baud_rate == 300  )   i = IDD300 ;
  277.        else if ( baud_rate == 1200 )   i = IDD1200;
  278.        else                            i = IDD9600;
  279.        CheckRadioButton( hWndDlg, IDD300, IDD9600,i );
  280.  
  281.        if      ( char_w == 11 && char_h == 11 ) i = IDDSMALL;
  282.        else if ( char_w == 22 && char_h == 11 ) i = IDDMED1 ;
  283.        else if ( char_w == 11 && char_h == 22 ) i = IDDMED2 ;
  284.        else                                     i = IDDLARGE;
  285.        CheckRadioButton( hWndDlg, IDDSMALL, IDDLARGE, i );
  286.  
  287.        comm = atoi( port_name+3 );
  288.        if      (  comm == 1 )  i = IDDCOM1;
  289.        else if (  comm == 2 )  i = IDDCOM2;
  290.        else if (  comm == 3 )  i = IDDCOM3;
  291.        else if (  comm == 4 )  i = IDDCOM4;
  292.        CheckRadioButton( hWndDlg, IDDCOM1, IDDCOM4, i );
  293.  
  294.        if      ( message_action == MSG_FLASH ) i = IDDFLASH  ;
  295.        else if ( message_action == MSG_BEEP  ) i = IDDBEEP   ;
  296.        else if ( message_action == MSG_DISP  ) i = IDDDISPLAY;
  297.        else                                    i = IDDOPEN   ;
  298.        CheckRadioButton( hWndDlg, IDDFLASH, IDDOPEN, i );
  299.        break;
  300.  
  301.    case WM_COMMAND:
  302.        switch( wParam ) {
  303.            case IDD300:
  304.            case IDD1200:
  305.            case IDD9600:
  306.                if      ( wParam == IDD300  )  baud =  300;
  307.                else if ( wParam == IDD1200 )  baud = 1200;
  308.                else                           baud = 9600;
  309.                CheckRadioButton( hWndDlg, IDD300, IDD9600, wParam );
  310.                break;
  311.  
  312.            case IDDSMALL:
  313.            case IDDMED1:
  314.            case IDDMED2:
  315.            case IDDLARGE:
  316.                if      ( wParam == IDDSMALL )  { w =  8; h =  8; }
  317.                else if ( wParam == IDDMED1  )  { w = 22; h = 11; }
  318.                else if ( wParam == IDDMED2  )  { w = 11; h = 22; }
  319.                else if ( wParam == IDDLARGE )  { w = 22; h = 22; }
  320.  
  321.                w *= (no_cols  + 6); /* Size window acording to new font */
  322.                h *= (no_lines + 6);
  323.                GetWindowRect(hWndTerm,(LPRECT)&rect);
  324.                MoveWindow( hWndTerm, rect.left, rect.top, w, h, TRUE);
  325.                if ((rect.right-rect.left > GetSystemMetrics(SM_CXICON)+10) ||
  326.                        (rect.bottom-rect.top > GetSystemMetrics(SM_CYICON)+10)) {
  327.                   CopyRect((LPRECT)&win_sz.size,(LPRECT)&rect);
  328.                   }
  329.  
  330.                CheckRadioButton( hWndDlg, IDDSMALL, IDDLARGE, wParam );
  331.                break;
  332.  
  333.            case IDDCOM1:
  334.            case IDDCOM2:
  335.            case IDDCOM3:
  336.            case IDDCOM4:
  337.                if      ( wParam == IDDCOM1 )  comm = 1;
  338.                else if ( wParam == IDDCOM2 )  comm = 2;
  339.                else if ( wParam == IDDCOM3 )  comm = 3;
  340.                else                           comm = 4;
  341.                CheckRadioButton( hWndDlg, IDDCOM1, IDDCOM4, wParam );
  342.                break;
  343.  
  344.            case IDDFLASH:
  345.            case IDDBEEP:
  346.            case IDDDISPLAY:
  347.            case IDDOPEN:
  348.                if      ( wParam == IDDFLASH   )  iconmode = MSG_FLASH;
  349.                else if ( wParam == IDDBEEP    )  iconmode = MSG_BEEP ;
  350.                else if ( wParam == IDDDISPLAY )  iconmode = MSG_DISP ;
  351.                else                              iconmode = MSG_OPEN ;
  352.                CheckRadioButton( hWndDlg, IDDFLASH, IDDOPEN, wParam );
  353.                break;
  354.  
  355.            case IDOK:
  356.                sprintf( port_name, "COM%d:", comm );
  357.                baud_rate = baud;
  358.                message_action = iconmode;
  359.                CloseComm(nCID);
  360.                i = TRUE;    /* Reopen the comm port with new speed & number */
  361.                if ( TermOpenComm() == FALSE ) {
  362.                    fileput("Unable to re-open the communications port");
  363.                    i = FALSE;
  364.                    }
  365.                EndDialog( hWndDlg, i );
  366.                break;
  367.  
  368.            case IDCANCEL:
  369.                EndDialog( hWndDlg, FALSE );
  370.                break;
  371.            default:
  372.                return( FALSE );
  373.            }
  374.        break;
  375.    default:
  376.        return( FALSE );
  377.    }
  378. return( TRUE );
  379. }
  380.  
  381.